
<script setup>
import { ref, getCurrentInstance, onMounted } from "vue";
import { showToast } from 'vant';
import axios from 'axios'
import uuid from '../utils/uuid'
const {
	ctx,
	proxy
} = getCurrentInstance();


onMounted(() => {
	 getUserList(); // --调用网络请求示例代码中的方法，获取数据。
	// addUser(); // --调用网络请求示例代码中的方法，添加数据。
	showToast({
		message: '顶部展示',
		position: 'top',
	});
	showToast('提示内容');
	console.log(uuid())
})
// --网络请求示例代码
const getUserList = () => {
	loadData('userList', {
		// --参数配置
	}, (res) => {
		console.log(res);
	}).catch(err => {
		console.log(err);
	})
}

// --网络请求示例代码
const addUser = () => {
	loadData('addUser', {
		// --参数配置
	}, (res) => {
		console.log(res);
	}).catch(err => {
		console.log(err);
	})
}
// --网络请求示例代码
const text = () => {
	loadData('xxx', {
		// --参数配置
	}, (res) => {
		console.log(res);
	}).catch(err => {
		console.log(err);
	})
}
const loadData = async (type, mode, callback) => {
	console.log(mode)
	let param, _res;
	switch (type) {
		case 'addUser':
			param = {
				text: '',
				userid: uuid()
			}
			_res = await postData(param, type);
			break;
		case 'userList':
			param = {
				id: 6
			}
			_res = await getData(param, type);
			break;
		default:
	}
	if (typeof callback === 'function') {
		// 数据加载完成回调函数
		callback(_res);
	}
}

const postData = (param, type) => {
	let url = '/api/api/' + type;
	return new Promise((resolve, reject) => {
		proxy.$api.postData(url, param).then((res) => {
			try {
				if (res.errcode == '0') {
					resolve(res);
				} else {
					console.log(res);
					reject('获取信息失败' + res.errmsg + param)
				}
			} catch (error) {
				console.log(error)
			}

		})
	})
}
const getData = (param, type) => {
	console.log(param, type)
	let url = '/api/users/userList';
	console.log(url)
	return new Promise((resolve, reject) => {
		proxy.$api.getData(url, param).then((res) => {
			console.log(res);
			if (res.status == '200') {
				resolve(res);
			} else {
				reject('获取信息失败' + res)
			}
		})
	})
}
</script>
<template>hehe
	<van-row>
		<van-col span="8">span: 8</van-col>
		<van-col span="8">span: 8</van-col>
		<van-col span="8">span:7</van-col>
	</van-row>
</template>
<style scoped lang="less">
h2 {
	color: #f3f3f3;
}
</style>